Skip to content

Conversation

bulbazord
Copy link

The implementation of the templated Get function contains UB. For example, the "GetDoubleUnaligned" unit test causes Get to perform an unaligned 8 byte read. This violates the double alignment requirement. Furthermore, it violates strict aliasing rules in C++. (We construct a const double * from a const uint8_t * and perform a read on the resulting double pointer).

DataExtractor should be able to read unaligned data to deal with different data formats, but we need to be careful to not perform unaligned reads/writes or violate strict aliasing rules.

rdar://160385383
(cherry picked from commit 40d4ea6)

The implementation of the templated `Get` function contains UB. For
example, the "GetDoubleUnaligned" unit test causes `Get` to perform an
unaligned 8 byte read. This violates the `double` alignment requirement.
Furthermore, it violates strict aliasing rules in C++. (We construct a
`const double *` from a `const uint8_t *` and perform a read on the
resulting double pointer).

DataExtractor should be able to read unaligned data to deal with
different data formats, but we need to be careful to not perform
unaligned reads/writes or violate strict aliasing rules.

rdar://160385383
(cherry picked from commit 40d4ea6)
@bulbazord
Copy link
Author

@swift-ci please test

@bulbazord bulbazord merged commit a1023f6 into swiftlang:stable/21.x Oct 21, 2025
3 checks passed
@bulbazord bulbazord deleted the 21.x-misaligned-load branch October 21, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant